package com.zr.feignclient.rabbitmq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import com.rabbitmq.client.Channel;
/**
 * Created by Lx on 2018/9/13.
 */
@Component
public class RabbitMQINT {
    //接收mq传过来的消息,不会自动创建消息队列，需要在客户端先创建消息队列，随后发送消息，才能接收到信息
//    @RabbitListener(queues = "test")
    //接收mq接收过来的信息，会自动创建消息队列，不需要再客户端创建消息队列，通过提供端发送消息，消费端就会接收到信息
    /*@RabbitListener(queuesToDeclare = @Queue("test1"))
    public void test(String a)throws Exception{
        System.out.println("rabbitMQ接收消息===="+a);
    }*/
    @RabbitListener(queuesToDeclare = @Queue("test1"))
    public void test(String a)throws Exception{
        System.out.println("rabbitMQ接收消息===="+a);
    }

   /* @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myMQExchange"),
            key = "fruit",
            value = @Queue("testMQ")
    ))
    public void myMQTest(String message){
        System.out.println("消息队列接收的信息"+message);
    }

    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myMQExchange"),
            key = "class",
            value = @Queue("testMQ1")
    ))
    public void classmyMQTest(String message){
        System.out.println("消息队列接收的信息"+message);
    }*/

   @Autowired
   private AmqpTemplate amqpTemplate;
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("orderMQ"),
            key = "parts",
            value = @Queue("partsTest")
    ))
    public void orderMq(String parts){
        System.out.println("jieshoude xinxi=="+parts);
        //去库存处理
        //返回消息
        amqpTemplate.convertAndSend("partsMQ","order","测试订单信息");
//        System.out.println("消息队列接收的信息,备件编码==="+parts.getCode()+"备件名称=="+parts.getName());
    }

}
